@echo off
:
: This batch file writes (or over-writes) a C# source file that looks something like this:
:	
:		namespace <NAMESPACE_NAME>
:		{
:			public static partial class <CLASS_NAME>				
:			{														
:				/// <summary> The date and time of the start of the build process for the assembly. </summary>	
:				public const string <MEMBER_NAME> = <CURRENT_DATE_AND_TIME>;		
:			}
:		}													
:
: This batch file is intended to be invoked as a pre-build event in a C# project.
: The generated C# source file is used to put the date & time of the build in the 
: assembly attribute AssemblyInformationalVersion, usually defined in AssemblyInfo.cs.
:
: This batch file takes 4 arguments:
:		1. output file path
:		2. the name of the namespace
:		3: the name of the class
:		4. the name of the member
:
: WARNING: the output file will be replaced EVEN IF IT'S READ-ONLY!
:
setlocal

if %4. equ . goto badArgs
if %5. neq . goto badArgs

set OUTFILE=%1

: Delete the output file, even if it's read-only, in case source control made it read-only.
del /F %OUTFILE%
echo // This file was generated automatically by %~n0%~x0	 >%OUTFILE%
echo namespace %2											>>%OUTFILE%
echo {														>>%OUTFILE%
echo 	public static partial class %3						>>%OUTFILE%
echo 	{ 													>>%OUTFILE%
echo 		/// ^<summary^> The date and time of the start of the build process for the assembly. ^</summary^>	>>%OUTFILE%
echo 		public const string %4 = "%DATE% %TIME:~,-3% by %USERNAME% on %COMPUTERNAME%";						>>%OUTFILE%
echo 	}													>>%OUTFILE%
echo }														>>%OUTFILE%

exit /B 0

: badArgs
echo Expecting four arguments: outputFilePath namespaceName className memberName

exit /B 1
